package com.erd.datacollect.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DataTool {
    private static Logger logger = LoggerFactory.getLogger(DataTool.class);
    public static String formatStrNum(String str){
        if(strIssBool(str)){
            return str;
        }
        return formatStrNum(str,null);
    }
    public static boolean strIssBool(String str){
        boolean check = "true".equalsIgnoreCase(str)||"false".equalsIgnoreCase(str);
        return check;
    }
    public static String formatStrNum(String str,String format){
        String result = "0.0";
        if(str==null||str.length()==0){
            return "0.0";
        }
        try {
            Double d = Double.parseDouble(str);
            if(format==null||format.length()==0){
                format="%.2f";
            }
            result = String.format(format,d);
        } catch (NumberFormatException e) {
            logger.error(e.toString());
        }
        return result;
    }
}
